package web.Data;

import domain.Warning;
import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/upWarningServlet")
public class UpWarningServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");

        //调用Service查询需要预警的节点
        User_Service user_service = new User_ServiceImpl();
        List<Warning> warnings = user_service.selectWarning();
        System.out.println(warnings);

        //把获取到的列表存入缓存返回给前台
        request.setAttribute("warning",warnings);
        request.getRequestDispatcher("/data/upWarning.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
